home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / STDLIB.PAK / ROTATE.CPP < prev    next >
Text File  |  1997-05-06  |  747b  |  32 lines

  1.  #include <algorithm>
  2.  #include <vector>
  3.  
  4.  using namespace std;
  5.  
  6.  int main ()
  7.  {
  8.    //
  9.    // Initialize a vector with an array of integers.
  10.    //
  11.    int arr[10] = {1,2,3,4,5,6,7,8,9,10};
  12.    vector<int> v(arr+0, arr+10);
  13.    //
  14.    // Print out elements in original (sorted) order.
  15.    //
  16.    cout << "Elements before rotate: " << endl << "     ";
  17.    copy(v.begin(), v.end(), ostream_iterator<int>(cout," "));
  18.    cout << endl << endl;
  19.    //
  20.    // Rotate the elements.
  21.    //
  22.    rotate(v.begin(), v.begin()+4, v.end());
  23.    //
  24.    // Print out the rotated elements.
  25.    //
  26.    cout << "Elements after rotate: " << endl << "     ";
  27.    copy(v.begin(), v.end(), ostream_iterator<int>(cout," "));
  28.    cout << endl;
  29.  
  30.    return 0;
  31.  }
  32.